package io.renren.modules.personnel.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.personnel.entity.FailedListEntity;
import io.renren.modules.personnel.service.FailedListService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 未通过名单
 *
 * @author Mark
 * @email sunlightcs@gmail.com
 * @date 2022-01-02 18:21:01
 */
@RestController
@RequestMapping("personnel/failedlist")
public class FailedListController {
    @Autowired
    private FailedListService failedListService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("personnel:failedlist:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = failedListService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{failedId}")
    @RequiresPermissions("personnel:failedlist:info")
    public R info(@PathVariable("failedId") Long failedId){
        FailedListEntity failedList = failedListService.getById(failedId);

        return R.ok().put("failedList", failedList);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("personnel:failedlist:save")
    public R save(@RequestBody FailedListEntity failedList){
        failedListService.save(failedList);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("personnel:failedlist:update")
    public R update(@RequestBody FailedListEntity failedList){
        ValidatorUtils.validateEntity(failedList);
        failedListService.updateById(failedList);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("personnel:failedlist:delete")
    public R delete(@RequestBody Long[] failedIds){
        failedListService.removeByIds(Arrays.asList(failedIds));

        return R.ok();
    }

}
